package cn.ava.system.controller;

import cn.ava.basic.utils.AjaxResult;
import cn.ava.basic.utils.PageList;
import cn.ava.system.domain.Systemdictionarydetail;
import cn.ava.system.query.SystemdictionarydetailQuery;
import cn.ava.system.service.ISystemdictionarydetailService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @ClassName: SystemdictionarydetailController
 * @Description: 系统字典明细控制层
 * @Author: Avavaava
 * @Date: 2022/7/1 9:27
 * @version: 23.53
 * 
 */
@RestController
@RequestMapping("/sysDictionarydetail")
public class SystemdictionarydetailController {

    // 实例化接口对象
    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailService;


    @GetMapping
    @ApiOperation(value = "查询所有部门")
    public List<Systemdictionarydetail> list() {
        return systemdictionarydetailService.loadAll();
    }
    

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID查询部门数据")
    public Systemdictionarydetail getById(@PathVariable("id") Long id) {
        return systemdictionarydetailService.getById(id);
    }


    @DeleteMapping("/{id}")
    public AjaxResult delete(@ApiParam(value = "主键",readOnly = true) @PathVariable("id") Long id) {
        try {
            systemdictionarydetailService.delete(id);
           return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }

    @DeleteMapping("/deleteAllTypeId/{id}")
    public AjaxResult deleteAllTypeId(@PathVariable("id") Long id) {
        try {
            systemdictionarydetailService.deleteAllTypeId(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }



    @PutMapping
    public AjaxResult addOrUpt(@RequestBody Systemdictionarydetail systemdictionarydetail) {
        try{
            if (systemdictionarydetail.getId() == null) {
                systemdictionarydetailService.add(systemdictionarydetail);
            }else {
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }


    @PostMapping
    public PageList<Systemdictionarydetail> queryDept(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
        return systemdictionarydetailService.queryData(systemdictionarydetailQuery);
    }


    @PatchMapping
    public AjaxResult batchDelete( @RequestBody Long[] id) {
        try {
            systemdictionarydetailService.batchDelete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setMessage("服务器崩溃！").setSuccess(false);
        }
    }


}
